<template>
	<div class="myGrowth">
		<div class="classIndex_h">
			<span v-if="roleBaseid(5)">孩子成绩</span>
			<span v-else>我的成绩</span>
		</div>
		<!--  -->
		<div class="classNotice_search clear">
			<div class="achievement_type fl">
				<template v-if="roleBaseid(5)">
					<router-link :to="{path: '/class/achieve/index', query: {id: path}}">
						孩子成长
					</router-link>
					<router-link :to="{path: '/class/achieve/growth', query:{id: path}}">
						孩子成绩
					</router-link>
				</template>
				<template v-else>
					<router-link :to="{path: '/class/achieve/index', query: {id: path}}">
						我的成长
					</router-link>
					<router-link :to="{path: '/class/achieve/growth', query:{id: path}}">
						我的成绩
					</router-link>
				</template>
			</div>
		</div>
		<!--  -->
		<template>
			<div class="myGrowth-chart">
				<IEcharts :option="option" />
			</div>
			<!--  -->
			<div class="myGrowth-tabel">
				<template>
					<el-table border :data="ahievement2" style="width: 100%">
						<el-table-column prop="name" label="名称" align="center" width="">
						</el-table-column>
						<el-table-column prop="sum" label="得分" align="center" width="">
						</el-table-column>
						<el-table-column prop="average" align="center" label="班级平均分" width="">
						</el-table-column>
						<el-table-column prop="rank" align="center" label="班级排名" width="">
						</el-table-column>
					</el-table>
				</template>
			</div>
		</template>
	</div>
</template>
<script>
import IEcharts from 'vue-echarts-v3/src/full.js';
export default {
	components: { IEcharts },
	data() {
		return {
			path: this.$route.query.id,
			ahievement: [],
			ahievement2: [],
			option: {
				tooltip: {
					trigger: 'axis',
				},
				toolbox: {
					show: true,
					feature: {
						saveAsImage: {
							pixelRatio: 5
						}
					}
				},
				dataZoom: [{
						height: 15,
						start: 0,
						end: 100,
					},
					{
						type: 'inside'
					}
				],
				legend: {
					y: '0',
					x: 'center',
					data: [],
				},
				toolbox: {
					show: true,
				},
				xAxis: [{
					type: 'category',
					data: []
				}],
				yAxis: [{
						type: 'value',
						name: '',
						splitNumber: 8,
						axisLabel: {
							formatter: function(value, index) {
								return value;
							}
						}
					},
					{
						type: 'value',
						name: '',
						min: 0,
						max: 30,
						interval: 5,
					}
				],
				series: []
			},

			identityVal: sessionStorage.getItem('parent_child_id') ? sessionStorage.getItem('parent_child_id') : this.$g.user_id, //缓存孩子id
			role: this.roleBaseid(5),
		}
	},
	created() {

	},
	watch: {

		'$store.state.changData': {
			handler(val, newval) {
				this.path = sessionStorage.getItem('classId')
				this.identityVal = sessionStorage.getItem('parent_child_id') ? sessionStorage.getItem('parent_child_id') : this.$g.user_id; //缓存孩子id
				this.getAhievement()
			},
			immediate: true
		}
	},
	computed: {
		changData() {
			return deep_clone(this.$store.state.changData);
		},
	},
	methods: {
		//获取科目
		getAhievement() {
			let success = res => {
				let data = res.data;
				this.ahievement = data.series;
				for (let i = 0; i < this.ahievement.length; i++) {

					this.option.series.push({
						name: this.ahievement[i].name,
						type: 'line',
						label: {
							normal: {
								show: true,
								position: 'top',
								formatter: '{c}'
							}
						},
						data: this.ahievement[i].data
					})
				}
				this.option.xAxis[0].data = data.testname
				this.option.legend.data = data.term
				this.ahievement2 = []
				for (let i = 0; i < data.testname.length; i++) {
					this.ahievement2.push({ name: data.testname[i] })

					this.ahievement2[i].sum = data.series[0].data[i]
					this.ahievement2[i].average = data.series[1].data[i]
					this.ahievement2[i].rank = data.series[2].data[i]

				}

			};

			let params = {
				studentid: this.$g.user_id,
				classid: this.path,
				order: 'time',
				falg: 1
			}
			this.$ajax.get('api/statistics/student_grade_static_list', { params, func: { success: success} })
			if (this.role) {
				params.studentid = this.identityVal
				this.$ajax.get('api/statistics/student_grade_static_list', { params, func: { success: success} })
			} else {
				this.$ajax.get('api/statistics/student_grade_static_list', { params, func: { success: success} })
			}

		},
	}
}
</script>